import { deepClone } from '@/utils'
// import req from '@/utils/request'
export default {
    data () {
        return {
            currentPage: 1,
            pageSizes: [10, 20, 30, 40],
            pageSize: 10,
            layout: "total, sizes, prev, pager, next, jumper",
            total: 100,
            query:''
        }
    },
    computed: {
        apiPager() {
            let params={
                pageNo: this.currentPage,
                pageSize: this.pageSize,
                // todo 判断name附加
            }
            if(this.query&&this.query.trim()!==''){
                params.name=this.query
            }
            return params
            // return {
            //     pageNo: this.currentPage,
            //     pageSize: this.pageSize,
            //     // todo 判断name附加
            // }
        },
        frontPager() {
            return deepClone({
                currentPage: this.currentPage,
                pageSizes: this.pageSizes,
                pageSize: this.pageSize,
                layout: this.layout,
                total: this.total,
            })
        }
    },
    methods:{
        handleSizeChange(val) {
            this.pageSize = val;
            this.currentPage = 1;
            console.log(`每页 ${val} 条`);
            this.load();
            // this.init();
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            console.log(`当前页: ${val}`);
            this.load();
            // this.init();
        },
        setTotal(total){
            this.total=total
        },
        setQuery(query){
            this.query=query
            this.currentPage = 1;
            this.load();
        }
    
        // // CRUD的混入内容
        // async init() {
        //     // 发请求
        //     let res = await req('/loan/list', {
        //         params: this.apiPager
        //     });
        //     console.log('加载数据:', res);
        // }
    }
}